package org.pupil.socket.server;

import org.pupil.filter.FilterData;
import org.pupil.filter.FilterResponse;
import org.pupil.filter.server.ServerBeforeFilter;
import org.pupil.socket.codec.RpcRequest;

/**
 * @Description: 服务提供方token拦截器
 * @Author: pupil
 * @Date: 2024/07/17 下午 6:43
 */
public class ServerTokenFilter implements ServerBeforeFilter {
    @Override
    public FilterResponse doFilter(FilterData<RpcRequest> filterData) {
        final RpcRequest rpcRequest = filterData.getObject();
        Object token = rpcRequest.getClientAttachments().get("token");
        if (!token.equals("pupil")){
            return new FilterResponse(false,new Exception("token 不正确,当前token为:" + token));
        }
        return new FilterResponse(true,null);
    }
}
